/* -----------------------------------------------------------------------
 * test gainCard
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
// based off of testUpdateCoins  example provided for class
    //int i;
    int seed = 1000;
    int numPlayer = 2;

	int r;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

	int player = 1;

	int failed = 0;

	int toFlag = 1;
		 // toFlag = 0 : add to discard
		  // toFlag = 1 : add to deck
		  // toFlag = 2 : add to hand
	
	memset(&G, 23, sizeof(struct gameState));   // clear the game state
	r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	
	//check gainCard fail for card not in supply
	if(-1 != gainCard(minion, &G, toFlag, player)){
		failed = 1;
		printf("Unittest 2: gainCard not -1 for card not in supply\n");
	}
	
	//check gain card added to deck
	gainCard(feast, &G, toFlag, player);
	if(feast != G.deck[player][10]){
		printf("Unittest 2: gainCard not added to deck%i\n", G.deck[player][10]);
		failed = 1;				
	}
	if(11 != G.deckCount[player]){
		printf("Unittest 2: gainCard deck count not increased%i\n", G.deck[player][10]);
		failed = 1;				
	}
	
	//check gaincard added to discard
	toFlag = 0;
	gainCard(feast, &G, toFlag, player);
	if(feast != G.discard[player][0]){
		printf("Unittest 2: gainCard not added to discard%i\n", G.discard[player][0]);
		failed = 1;				
	}
	if(1 != G.discardCount[player]){
		printf("Unittest 2: gainCard discard count not increased%i\n", G.deck[player][10]);
		failed = 1;				
	}
	//check gain card added to hand
	toFlag = 2;
	gainCard(feast, &G, toFlag, player);
	if(feast != G.hand[player][0]){
		printf("Unittest 2: gainCard not added to hand%i\n", G.hand[player][0]);
		failed = 1;				
	}
	if(1 != G.discardCount[player]){
		printf("Unittest 2: gainCard, hand count not increased%i\n", G.deck[player][10]);
		failed = 1;				
	}
	
	//check supply count decreased
	//starts at 10 should be decreased 3 times, count should = 7
	if(7 != G.supplyCount[feast]){
		printf("Unittest 2: supply count not decreased%i\n", G.supplyCount[feast]);
		failed = 1;				
	}
	
	if(failed == 0){
		printf("unittest2: gainCard - All tests passed!\n");
	}


    return 0;
}